package com.iwdnb.gkgz.common.utils;

import java.math.BigDecimal;
import java.math.RoundingMode;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;

import cn.hutool.core.date.DateUtil;
import com.iwdnb.bmnf.common.utils.HttpClientUtils;
import com.iwdnb.gkgz.common.model.dto.StockMinuteData;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.collections4.CollectionUtils;

@Slf4j
public class StockMinuteUtils {



    private static BigDecimal suggestSellPrice(List<StockMinuteData> list) {
        double[] array = new double[list.size()];
        List<Double> priceList = new ArrayList<>();
        for (int i = 0; i < list.size(); i++) {
            StockMinuteData data = list.get(i);
            array[i] = data.getPrice().doubleValue();
        }
        double price = GM.gm(array, 3);
        return new BigDecimal(price).setScale(2, RoundingMode.HALF_UP);
    }

    private static BigDecimal getCurrentPrice(List<StockMinuteData> list) {
        return list.get(list.size() - 1).getPrice();
    }

    public static void main(String[] args) {
        List<StockMinuteData> list = StockUtils.getRealtimeMinuteData("sh601005");
        System.out.println(JSON.toJSONString(list));
        List<StockMinuteData> morningList = new ArrayList<>();
        String time = "1029";
        for (StockMinuteData data : list) {
            if (data.getMinute().equals(time)) {
                break;
            }
            morningList.add(data);
        }
        BigDecimal price = suggestSellPrice(morningList);
        System.out.println("suggestSellPrice:" + price);
        System.out.println("currentPrice:" + getCurrentPrice(list));
    }

}
